﻿CREATE PROCEDURE [Cucina].[SP_Menu_Data]
	@TimeStamp datetime
AS
	DECLARE @MenuVersionGuid uniqueidentifier
	DECLARE @MenuVersionTimeStamp DateTime

	SELECT TOP 1 @MenuVersionGuid = MH.MenuVersionGuid, @MenuVersionTimeStamp = MH.TimeStamp_Insert
	FROM [Cucina].[MenuHash] MH
	ORDER BY TimeStamp_Insert DESC

	SELECT MenuID, InizioValidita, FineValidita, NomeEvento, @MenuVersionGuid AS MenuVersionGuid, @MenuVersionTimeStamp AS MenuVersionTimeStamp
	FROM [Cucina].[Menu]
	WHERE (@TimeStamp > InizioValidita AND FineValidita IS NULL) OR (@TimeStamp BETWEEN InizioValidita AND FineValidita)
RETURN 0